home *** CD-ROM | disk | FTP | other *** search
/ HTBasic 9.3 / HTBasic 9.3.iso / 83win / data1.cab / DLL_Toolkit / Source / HTBMail / HTBMAIL.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-03-02  |  3.0 KB  |  121 lines

  1. /*************************************************************
  2. HTBmail.dll
  3.  
  4. Copyright 1999 TransEra Corporation
  5.  
  6. htbmail.cpp  
  7.       
  8. With help from http://www.codeguru.com/internet/imapi.shtml 
  9. *************************************************************/
  10.  
  11. #include "stdafx.h"
  12. #include "HTBMAIL.h"
  13. #include <mapi.h>
  14. #include "imapi.h"
  15.  
  16. #ifdef _DEBUG
  17. #define new DEBUG_NEW
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21.  
  22. BEGIN_MESSAGE_MAP(CHTBMAILApp, CWinApp)
  23. END_MESSAGE_MAP()
  24.  
  25. CHTBMAILApp::CHTBMAILApp() 
  26. {    
  27. }
  28.  
  29. CHTBMAILApp theApp;
  30.  
  31. BOOL CHTBMAILApp::InitInstance() 
  32. {
  33.     return TRUE;
  34. }
  35.  
  36.  
  37. /////////////////////////////////////////////////////////////////////////////
  38. /*
  39.     Function:        Sendmailattach
  40.  
  41.     Description:    Sends an e-mail message WITH an attatchment
  42.  
  43.     Return type:    void 
  44.     Argument:        char *MAddress
  45.     Argument:        char *MSubject
  46.     Argument:        char *MAttach
  47.     Argument:        char *MText
  48.  
  49.     Notes:            This funtion will send an e-mail message with 
  50.                     an attatchment.  This is done through the 
  51.                     MAPI interface which i wrapped in the
  52.                     IMapi.cpp file.
  53.         
  54. */
  55. void Sendmailattach(char *MAddress, char *MSubject, char *MAttach, char *MText) 
  56. {
  57. int err; 
  58. int len = 0;
  59. char Delim[C_DELIM] = COMMA;
  60. char Addr[MAX_ADDR] = ADDR;
  61. char *pAddr = Addr;
  62.  
  63. CIMapi mail;
  64.     
  65. pAddr = strtok(MAddress, Delim);
  66.     
  67. while (pAddr != NULL)                                         //  While loop for multiple recipients
  68. {    
  69.     mail.To(pAddr);                                            //  To 
  70.     pAddr = strtok(NULL, Delim);
  71. }                                    
  72.     mail.Subject(MSubject);                                    //  Subject            
  73.     len = strlen(MAttach);                                    //    Check length of path and filename  
  74.     err = SearchPath(NULL, MAttach, NULL, len, NULL, NULL);    //  Is the file really there?
  75.     if (err > 0)                                             //  if it is, lets finish sending it
  76.     {
  77.         mail.Attach(MAttach);                                //  Attaching a file 
  78.         mail.Text(MText);                                    //  Body
  79.         mail.Send();                                        //  Send it! 
  80.     }
  81.     else                                                     //  If it's not lets tell the user.        
  82.     {
  83.         AfxMessageBox("Attachment Filename or Path incorrect:\nAborting Mail send!");
  84.     }                                                        //  Then we die.
  85. }
  86.  
  87.  
  88. /////////////////////////////////////////////////////////////////////////////
  89. /*
  90.     Function:        Sendmail
  91.  
  92.     Description:    Sends Email message from HTBasic
  93.  
  94.     Return type:    void 
  95.     Argument:        char *MAddress
  96.     Argument:        char *MSubject
  97.     Argument:        char *MText
  98.  
  99.     Notes:            This function will use the MAPI interface defined
  100.                     and wrapped in the IMapi class defined in IMapi.cpp.
  101.                     This sends a regular e-mai lmessage WITHOUT and attatchment.
  102.         
  103. */
  104. void Sendmail(char *MAddress, char *MSubject, char *MText) 
  105. {
  106. char Delim[C_DELIM] = COMMA;                                        //  Defined in HTBMAIL.h
  107. char Addr[MAX_ADDR] = ADDR;                                        //  Defined in HTBMAIL.h
  108. char *pAddr = Addr;
  109.  
  110.     CIMapi mail;
  111.     pAddr = strtok(MAddress, Delim);
  112.  
  113.     while (pAddr != NULL)                                         //  While loop for multiple recipients
  114.     {
  115.     mail.To(pAddr);                                            //  To 
  116.     pAddr = strtok(NULL, Delim);
  117. }
  118.     mail.Subject(MSubject);                                    //  Subject        
  119.     mail.Text(MText);                                        //  Body
  120.     mail.Send();                                            //  Send it! 
  121. }